home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / UI Classes / Windows / WindowManager.h < prev   
Encoding:
C/C++ Source or Header  |  1998-06-15  |  5.5 KB  |  196 lines  |  [TEXT/CWIE]

  1. #ifndef __WINDOWMANAGER__
  2. #define __WINDOWMANAGER__
  3. #pragma once
  4.  
  5. #include "Module.h"
  6. #include "EventFilter.h"
  7. #include <Windows.h>
  8.  
  9. class WindowManager;
  10.  
  11. const WindowRef        kBeforeFirstWindow = (WindowRef) -1;
  12. const short            kScreenEdgeSlop            = 4;
  13. const short            kSpaceForFinderIcons    = 64;
  14. const short            kMinimumTitleBarHeight    = 21;
  15. const short            kMinimumWindowSize        = 32;
  16.  
  17. enum
  18.     {
  19.     kScrollbarWidth = 16,    //    width of a standard Macintosh scrollbar
  20.     kScrollbarTweak = 2        //    left edge = rightedge - kScrollbarWidth + kScrollbarTweak
  21.     };
  22.  
  23.  
  24. enum WindowLayer
  25. {
  26.     kAnyWindowLayer = -1,
  27.     kNormalWindowLayer = 0,
  28.     kFloatingWindowLayer,
  29. //    kModalWindowLayer,
  30.     kNumWindowLayers
  31. };
  32.  
  33.  
  34. class WindowManager : public TModule, public EventFilter
  35. {
  36.     DeclareClass2Base(WindowManager, TModule, EventFilter);
  37.  
  38. protected:
  39.     RgnHandle    fScratchRgn;
  40.     bool        fHasColorQuickdraw;
  41.     bool        fHasDisplayManager;
  42.  
  43. public:
  44.     WindowManager();
  45.     virtual ~WindowManager();
  46.  
  47.     virtual bool    Validate(void);        // Check against system, possibly re-order
  48.     virtual void    Initialize(void);
  49.     virtual void    Finalize(void);
  50.     virtual bool    Initialized(void);
  51.     virtual bool    InitializeCalled(void);    // Return true if you have been initialized
  52.  
  53.     virtual bool    FilterEvent(ToolboxEvent& evt);
  54.  
  55.     //
  56.     // Window manager replacement functions - call as needed to support floating windows, etc.
  57.     //
  58.     virtual    WindowRef        GetNewWindow(short windowID, WindowRef behind, WindowLayer layer = kNormalWindowLayer);
  59.     virtual    WindowRef        NewWindow(const Rect &boundsRect, ConstStr255Param title, bool visible, short theProc, WindowRef behind, bool goAwayFlag, long refCon, WindowLayer layer = kNormalWindowLayer);
  60.     virtual    void            DisposeWindow(WindowRef aWindow);
  61.  
  62.     virtual    void            SelectWindow(WindowRef aWindow);
  63.     virtual    void            UpdateWindow(WindowRef aWindow);
  64.     virtual    void            ActivateWindow(WindowRef aWindow);
  65.     virtual    void            DeactivateWindow(WindowRef aWindow);
  66.     virtual    void            ShowWindow(WindowRef aWindow);
  67.     virtual    void            HideWindow(WindowRef aWindow);
  68.     virtual    void            CloseWindow(WindowRef aWindow);
  69.  
  70.     virtual    void            SuspendApplication();
  71.     virtual    void            ResumeApplication();
  72.     virtual    void            BeginModalDialog();
  73.     virtual    void            EndModalDialog();
  74.  
  75.     virtual WindowLayer        GetWindowLayer(WindowRef aWindow);
  76.     virtual WindowRef        FrontWindow(WindowLayer layer = kNormalWindowLayer);
  77.     virtual WindowRef        BackWindow(WindowLayer layer = kNormalWindowLayer);
  78.     virtual WindowRef        GetNthWindow(long index, WindowLayer layer = kNormalWindowLayer);
  79.     virtual WindowRef        GetNamedWindow(ConstStr255Param winName, WindowLayer layer = kNormalWindowLayer);
  80.     virtual long            GetWindowIndex(WindowRef aWindow, WindowLayer layer = kNormalWindowLayer);
  81.  
  82.     virtual bool            IsWindowVisible(WindowRef aWindow);
  83.     virtual bool            IsWindowHilited(WindowRef aWindow);
  84.     virtual bool            IsWindowModal(WindowRef aWindow);
  85.     virtual bool            IsWindowFloating(WindowRef aWindow);
  86.     virtual bool            IsDialogWindow(WindowRef aWindow);
  87.  
  88.     virtual bool            PointInStructureRgn(WindowRef aWindow, Point pt);
  89.     virtual bool            PointInContentRgn(WindowRef aWindow, Point pt);
  90.     virtual Rect            GetWindowStructureBounds(WindowRef aWindow);
  91.     virtual Rect            GetWindowContentBounds(WindowRef aWindow);
  92.  
  93.     virtual void            SetWindowBounds(WindowRef aWindow, Rect newBounds);
  94.     virtual void            DragWindow(WindowRef aWindow, Point startPoint);
  95.     virtual void            NudgeWindow(WindowRef aWindow, short horizontalDistance, short verticalDistance);
  96.     virtual void            GrowWindow(WindowRef aWindow, Point startPoint, const Rect* resizeLimits = nil);
  97.     virtual void            ZoomWindow(WindowRef aWindow, short zoomState, const Rect* perfectWindowRect = nil);
  98.  
  99.     virtual void            DrawWindowGrowIcon(WindowRef aWindow);
  100.  
  101. protected:
  102.     virtual void            HiliteShowHideFloatingWindows(bool active, bool hide);
  103. };
  104.  
  105. class WithWindowManagerPort
  106. {
  107. private:
  108.     GrafPtr    fSavedPort;
  109.     
  110. public:
  111.     WithWindowManagerPort()        { GrafPtr wmPort; ::GetPort(&fSavedPort); ::GetWMgrPort(&wmPort); ::SetPort(wmPort); }
  112.     ~WithWindowManagerPort()    { ::SetPort(fSavedPort); }
  113. };
  114.  
  115.  
  116. class WithWindowPort
  117. {
  118. private:
  119.     GrafPtr    fSavedPort;
  120.     
  121. public:
  122.     WithWindowPort(WindowRef aWindow)    { ::GetPort(&fSavedPort); ::SetPortWindowPort(aWindow); }
  123.     ~WithWindowPort()                    { ::SetPort(fSavedPort); }
  124. };
  125.  
  126.  
  127. class WindowListIterator
  128. {
  129. private:
  130.     WindowRef    fCurWindow;
  131.  
  132. public:
  133.     WindowListIterator()        { fCurWindow = ::FrontWindow(); }
  134.     ~WindowListIterator()        { }
  135.     
  136.     bool        More()            { return ::GetNextWindow(fCurWindow) != nil; }
  137.     WindowRef    First()            { return fCurWindow = ::FrontWindow(); } 
  138.     WindowRef    Next()            { return fCurWindow ? fCurWindow = ::GetNextWindow(fCurWindow) : nil; }
  139.  
  140. #if 0    
  141. {
  142.     Assert(layer == kNormalWindow);
  143.     Assert(index > 0);
  144.     
  145.     WindowRef win = FrontNonFloatingWindow();
  146.     
  147.     while (win != nil && --index >= 0)
  148.     {
  149.         if (index == 0)
  150.         {
  151.             return GetWindowObject(win);
  152.         }
  153.         
  154.         win = GetNextWindow(win);
  155.     }
  156.  
  157.     return nil;
  158. }
  159. #endif
  160.  
  161. };
  162.  
  163.  
  164. #if STRICT_WINDOWS && defined(__cplusplus)
  165.  
  166. // I kind of like to be able to see what's going on in the debugger
  167. // (note that this is just as secure as what apple's doing)
  168.  
  169. struct OpaqueWindowRef : private CGrafPort
  170. {
  171. private:
  172. //    CGrafPort                        port;
  173.     short                            windowKind;
  174.     bool                            visible;
  175.     bool                            hilited;
  176.     bool                            goAwayFlag;
  177.     bool                            spareFlag;
  178.     RgnHandle                        strucRgn;
  179.     RgnHandle                        contRgn;
  180.     RgnHandle                        updateRgn;
  181.     Handle                            windowDefProc;
  182.     Handle                            dataHandle;
  183.     StringHandle                    titleHandle;
  184.     short                            titleWidth;
  185.     ControlRef                        controlList;
  186.     OpaqueWindowRef*                nextWindow;
  187.     PicHandle                        windowPic;
  188.     long                            refCon;
  189. };
  190.  
  191. #endif // STRICT_WINDOWS && defined(__cplusplus)
  192.  
  193.  
  194. #endif // __WINDOWMANAGER__
  195.  
  196.